package com.xie.authority_system.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xie.authority_system.entity.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author XIEJINGCHENG
* @description 针对表【sys_role(角色表)】的数据库操作Mapper
* @createDate 2024-01-08 14:45:27
* @Entity com.xie.authority_system.entity.Role
*/
public interface RoleMapper extends BaseMapper<Role> {

    /**
     * 查找该角色id关联的用户id数量
     * @param roleId
     * @return
     */
    @Select("select count(1) from sys_user_role where role_id = #{roleId}")
    int getRoleCountByRoleId(Long roleId);

    /**
     * 删除该角色对应的权限列表
     * @param roleId
     */
    @Delete("delete from sys_role_permission where role_id = #{roleId}")
    void deleteRolePermissionByRoleId(Long roleId);

    /**
     * 保存角色权限信息
     * @param roleId
     * @param permissionIds
     * @return
     */
    int saveRolePermission(@Param("roleId") Long roleId, @Param("permissionIds") List<Long> permissionIds);

    /**
     * 查询角色id所拥有的角色id
     * @param userId
     * @return
     */
    @Select("select role_id from sys_user_role where user_id = #{userId}")
    List<Long> findRoleIdByUserId(Long userId);
}




